<?php
namespace Admin\Controller;
use Think\Controller;


class CatController extends Controller {

    public function catadd(){
        if (!IS_POST) {
            if (!checkCookie()) {
                $this->redirect('Admin/Index/login');
            }
            $this->display();
        }else{
            $catModel = D('cat');
            $_POST['is_show'] = 1;
            $_POST['utime']=$_POST['ctime'] = time();
            if ($catModel->add($_POST)) {
                $this->success('添加成功',(U('Admin/cat/catlist')));
            }else{
                $this->error('添加失败');
            }
        }
    }   

    public function catlist(){
        if (!checkCookie()) {
            $this->redirect('Admin/Index/login');
        }
        $catModel = D('cat');
        $cats = $catModel ->select(); 
        $this->assign('cats',$cats); 
        $this->display();
    }

    public function catedit(){
        if (!checkCookie()) {
            $this->redirect('Admin/Index/login');
        }
        $catModel = D('cat');
    	if (!IS_POST) {
            $cat_id = I('cid');
            $cat  = $catModel->find($cat_id); 
            $this->assign('cat',$cat); 
            $this->display();
    	}else{
            if ($catModel->where('cid='.$_POST['cid'])->save($_POST)) {
                 $this->success('修改成功',(U('Admin/art/artlist')));
            }else{
                $this->success('修改失败');
            }
        }
    }
}